package com.shijianchen.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shijianchen.projo.dicts.Dict;
import com.shijianchen.service.SpDictService;
import com.shijianchen.service.SpShopUserService;
import com.shijianchen.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 公共接口控制类
 */

@RestController
@RequestMapping("/pro-api/")
public class CommonController {
    @Autowired
    private SpDictService spDictService;
    @Autowired
    private SpShopUserService spShopUserService;
    /* 获取接口地址 */
    @GetMapping("/dicts/{type}")
    public Result<Object> getDicts(@PathVariable String type){
        ArrayList<Map<String,Object>> arrayList = new ArrayList<>();

        switch (type){
            case "shop_user":
                arrayList = spShopUserService.selectListForMap();
                break;
            default:
                arrayList = getCommonDictList(type);
        }
        return Result.ok(arrayList);
    }
    public ArrayList<Map<String,Object>> getCommonDictList(String type){
        List<Dict> dict = spDictService.getDict(type);
        ArrayList<Map<String,Object>> arrayList = new ArrayList<>();
        dict.forEach((dict1)->{
            Map<String,Object> dictMap = new HashMap<>();
            dictMap.put("label",dict1.getName());
            dictMap.put("value",dict1.getCode());
            dictMap.put("tag",dict1.getTag());
            arrayList.add(dictMap);
        });
        return arrayList;
    }
}
